from django.db import models

#导入时间域
from django.utils import timezone


#基类
class Base(models.Model):

	#创建时间
	create_time = models.DateTimeField(default=timezone.now,null=True)

	class Meta:
		abstract = True


# 角色表
class Relo(Base):
	id = models.AutoField(primary_key=True)
	name = models.CharField(max_length=100)

	class Meta:
		db_table = 'relo'


# 用户类
class User(Base):
	id = models.AutoField(primary_key=True)
	username = models.CharField(max_length=100)
	password = models.CharField(max_length=200)
	phone = models.CharField(max_length=11)
	email = models.CharField(max_length=24)
	nickname = models.CharField(max_length=24)
	role = models.ForeignKey(Relo, on_delete=models.SET_NULL, null=True, default=2)
	photo = models.CharField(max_length=255)
	base64photo = models.TextField()
	upyunimg = models.CharField(max_length=200)

	class Meta:
		db_table = 'user'


# 节点表
class Node(Base):
	id = models.AutoField(primary_key=True)
	node_name = models.CharField(max_length=100)

	class Meta:
		db_table = 'node'


# 权限表
class Access(Base):
	id = models.AutoField(primary_key=True)
	role = models.ForeignKey(Relo, on_delete=models.SET_NULL, null=True)
	node = models.ForeignKey(Node, on_delete=models.SET_NULL, null=True)

	class Meta:
		db_table = "access"


class WorkType(Base):
	id = models.AutoField(primary_key=True)
	name = models.CharField(max_length=100)
	custom = models.TextField()
	approver = models.CharField(max_length=255)

	class Meta:
		db_table = "worktype"


# 工单表
class Work(Base):
	id = models.AutoField(primary_key=True)
	user = models.ForeignKey(User,on_delete=models.CASCADE)
	work_data = models.TextField(max_length=500)
	work_type = models.ForeignKey(WorkType, on_delete=models.CASCADE)
	next_id = models.CharField(max_length=255)
	img = models.CharField(max_length=255)
	base64img = models.TextField()
	upyunimg = models.CharField(max_length=200)

	class Meta:
		db_table = "work"


# 任务表
class Task(Base):
	id = models.AutoField(primary_key=True)
	work = models.ForeignKey(Work, on_delete=models.CASCADE)
	uid = models.CharField(max_length=255)
	state = models.IntegerField(default=0)
	refuse = models.CharField(max_length=255)
	class Meta:
		db_table = "task"


class BlackList(Base):
	id = models.AutoField(primary_key=True)
	ip = models.CharField(max_length=255)

	class Meta:
		db_table = 'blacklist'


class Log(Base):
	id = models.AutoField(primary_key=True)
	uid = models.IntegerField()
	log = models.CharField(max_length=255)
	class Meta:
		db_table = 'log'